package com.wan37.logic.chat.service.impl;

import com.wan37.logic.chat.dao.PrivateChatDao;
import com.wan37.logic.chat.domain.entity.PrivateChatDO;
import com.wan37.logic.chat.domain.vo.ChatVO;
import com.wan37.logic.chat.service.PrivateChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-07-27 15:28
 **/
@Service("privateChatService")
public class PrivateChatServiceImpl implements PrivateChatService {
    @Autowired
    private PrivateChatDao privateChatDao;

    @Override
    public boolean update(ChatVO chatVO, String receiverId) {
        return privateChatDao.update(new PrivateChatDO(chatVO, receiverId));
    }

    @Override
    public boolean save(ChatVO chatVO, String receiverId) {
        return privateChatDao.add(new PrivateChatDO(chatVO, receiverId));
    }
    @Override
    public boolean delete(int id) {
        return privateChatDao.delete(id);
    }

    @Override
    public boolean deleteBySenderIdAndReceiverId(String senderId, String receiverId) {
        return false;
    }

    @Override
    public List<ChatVO> getPrivateChatDOBySenderIdAndReceiverId(String senderId, String receiverId) {
        List<PrivateChatDO> privateChatDOList = privateChatDao
                .getPrivateChatDOBySenderIdAndReceiverId(senderId, receiverId);
        List<ChatVO> chatVOList = null;
        if (privateChatDOList != null){
            chatVOList = new ArrayList<>();
            for (PrivateChatDO privateChatDO : privateChatDOList){
                chatVOList.add(new ChatVO(privateChatDO));
            }
        }
        return chatVOList;
    }

    @Override
    public List<ChatVO> getPrivateChatDOBySenderId(String senderId, String receiverId) {
        return null;
    }
}
